package com.oocl.handlebatchdata.comparator;

import java.util.Comparator;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.oocl.handlebatchdata.customer.Customer;

public class BirthdayComparator implements Comparator<Customer>{
	
	public int compare(Customer o1, Customer o2) {
		int result;
		SimpleDateFormat sdf=new SimpleDateFormat("YYYY-MM-DD");
		try {
			Date d1=sdf.parse(o1.getBirthday());
			Date d2=sdf.parse(o2.getBirthday());
			result=(d1.compareTo(d2));
			if(result==0){
				result=o1.getName().compareTo(o2.getName());
			}
			if(result==0){
				result=o1.getEmail().compareTo(o2.getEmail());
				
			}
			return result;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}

}
